package com.itheima.web.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author huyoufu <https://github.com/huyoufu>
 * @TIME 2020-08-11 15:16
 * @description
 * Converter<S, T>
 */

/*
    自定义类型转换器:
    S就是前端传递的参数类型 就是字符串
    T 目标类型
*/
public class MyDateConverter implements Converter<String, Date> {

    @Override
    public Date convert(String s) {
        //参数s就是前端传过来日期字符串 2018-08-03

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date=null;
        try {
            date = sdf.parse(s);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return date;
    }
}
